package clustersimulator;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import net.sf.javaml.core.Instance;
import net.sf.javaml.core.DenseInstance;
import java.util.ArrayList;

public class ProcessingClusterTest {
	
	ProcessingCluster pc;
	Job j;
	ArrayList<Job> fJobs;

	@Before
	public void setUp() throws Exception {
	    Instance centroid = new DenseInstance(new double[] {0.0, 0.0});
	    fJobs = new ArrayList<Job>(128);
	    pc = new ProcessingCluster(100,centroid,fJobs);
	    j = new Job(1, 8, 3, 0);
	    j.setTimeAssigned(2);
	}

	@Test
	public void testAssignJob() {
	    pc.assignJob(j);
	    assertFalse(pc.isAvailable());
	}

	@Test
	public void testProcessJob() {
	    pc.assignJob(j);
	    int clock = 2;
	    while (!pc.isAvailable()) {
		pc.processJob(clock);
		clock++;
	    }
	    assertTrue(j.getTimeFinished() == 4);
	    assertTrue(pc.getIdleNodeCycles() == 276);
	    assertTrue(fJobs.get(0).getJobID() == j.getJobID());
	}
}
